package com.sx.gongzhong.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RatingBar;

import com.sx.gongzhong.BaseActivity;
import com.sx.gongzhong.R;
import com.sx.gongzhong.pest.AddEvaluationPest;
import com.sx.gongzhong.utils.BaseUtil;
import com.sx.gongzhong.utils.ToastUtils;
import com.sx.gongzhong.view.IVoidView;
import com.sx.gongzhong.widget.LoadDialog;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 评价页面
 * Created by admin on 2017/11/27.
 */

public class EvalActivity extends BaseActivity {
    @BindView(R.id.et_evaluation)
    EditText etEvaluation;
    @BindView(R.id.ratingbar)
    RatingBar ratingbar;

    private String appealId;

    @Override
    public void setUI(Bundle savedInstanceState) {
        setContentView(R.layout.activity_eval);
        setTitle("评价");
        setTitleRight("提交");
        ButterKnife.bind(this);
        appealId = getIntent().getStringExtra("appealId");
    }

    @OnClick({R.id.tv_right})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tv_right:
                if (BaseUtil.isEmpty(etEvaluation.getText().toString().trim())){
                    ToastUtils.showToast(EvalActivity.this,"请输入内容");
                    return;
                }
                LoadDialog.show(EvalActivity.this,"提交中...");
                new AddEvaluationPest(new IVoidView() {
                    @Override
                    public void voidView(String s) {
                        LoadDialog.dismiss(EvalActivity.this);
                        ToastUtils.showToast(EvalActivity.this,"评价成功");
                        setResult(RESULT_OK);
                        finish();
                    }
                    @Override
                    public void showError(String message) {
                        LoadDialog.dismiss(EvalActivity.this);
                        ToastUtils.showToast(EvalActivity.this,message);
                    }
                }).addEvaluation(appealId,( int)ratingbar.getRating(), etEvaluation.getText().toString().trim());
                break;
        }
    }
}
